=========================================================================== BBS: The Abacus * HST/DS * Potterville MI Date: 03-01-93 (03:01) Number: 56 From: DIK COATES Refer#: NONE To: JIM COYLE Recvd: NO Subj: Crc32 2/2 Conf: (35) Quick Basi --------------------------------------------------------------------------- Part 2 of 2 - - - - - CUT HERE WITH SHARPENED END OF BEER CAN - - - - - crcstr proc far push bp mov bp,sp ;create stack frame les si,crcptr mov ax,es:[si] mov dx,es:[si+2] ;dx:ax -> crcout mov cx,srclen ;cx -> source length les si,srcptr ;es:si -> source buffer mov di,offset crctable ;cs:di -> crctable crcNext: mov bh,al ;save crcout & 0x000000ff mov al,ah ;(crcout >> 8) & 0x00ffffff mov ah,dl mov dl,dh xor dh,dh mov bl,es:[si] ;*src++ inc si xor bl,bh ;crcval & 0x000000ff xor bh,bh shl bx,1 shl bx,1 xor ax,cs:[di+bx] xor dx,cs:[di+bx+2] dec cx jcxz crcDone mov bh,al ;save crcout & 0x000000ff mov al,ah ;(crcout >> 8) & 0x00ffffff mov ah,dl mov dl,dh xor dh,dh mov bl,es:[si] ;*src++ inc si xor bl,bh ;crcval & 0x000000ff xor bh,bh shl bx,1 shl bx,1 xor ax,cs:[di+bx] xor dx,cs:[di+bx+2] dec cx jcxz crcDone mov bh,al ;save crcout & 0x000000ff mov al,ah ;(crcout >> 8) & 0x00ffffff mov ah,dl mov dl,dh xor dh,dh mov bl,es:[si] ;*src++ inc si xor bl,bh ;crcval & 0x000000ff xor bh,bh shl bx,1 shl bx,1 xor ax,cs:[di+bx] xor dx,cs:[di+bx+2] dec cx jcxz crcDone mov bh,al ;save crcout & 0x000000ff mov al,ah ;(crcout >> 8) & 0x00ffffff mov ah,dl mov dl,dh xor dh,dh mov bl,es:[si] ;*src++ inc si xor bl,bh ;crcval & 0x000000ff xor bh,bh shl bx,1 shl bx,1 xor ax,cs:[di+bx] xor dx,cs:[di+bx+2] loop crcNext crcDone: les si,crcptr mov es:[si],ax mov es:[si+2],dx pop bp ret 10 ;dispose of 10 parameter bytes crcstr endp code ends end - - - - - CUT HERE WITH SHARPENED END OF BEER CAN - - - - - Regards Dik, Oshawa, Canada ... Wanted Dead or Alive: 1 pink rabbit with a drum ___ Blue Wave/QWK v2.10 --- Maximus 2.00 * Origin: Durham Systems (ONLINE!) (1:229/110) SEEN-BY: 1/211 11/2 4 13/13 101/1 108/89 109/25 110/69 114/5 123/19 124/1 SEEN-BY: 153/752 154/40 77 157/2 159/100 125 430 950 203/23 209/209 280/1 SEEN-BY: 390/1 396/1 15 397/2 2230/100 3603/20 =========================================================================== BBS: The Abacus * HST/DS * Potterville, MI Date: 03-08-93 (12:19) Number: 249 From: CORIDON HENSHAW Refer#: NONE To: BRYAN NYLIN Recvd: NO Subj: Looking For Crc32 Code Conf: (35) Quick Basi --------------------------------------------------------------------------- Hello Bryan! Friday March 05 1993, Bryan Nylin writes to All: BN> I am looking for a function that will return the CRC-32 code for a BN> string that is passed to it. I should make this a FAQ or something... Here's CRC32 and CRC16 code: === BEGIN: CRC.BAS === DECLARE FUNCTION CRC16& (Block$) DECLARE FUNCTION CRC32& (Block$) DEFINT A-Z FUNCTION CRC16& (B$) 'Calculates CRC for Each Block DIM Power(0 TO 7) 'For the 8 Powers of 2 DIM CRC AS LONG FOR I = 0 TO 7 'Calculate Once Per Block to Power(I) = 2 ^ I ' Increase Speed Within FOR J NEXT I ' Loop CRC = 0 'Reset for Each Text Block FOR I = 1 TO LEN(B$) 'Calculate for Length of Block ByteVal = ASC(MID$(B$, I, 1)) FOR J = 7 TO 0 STEP -1 TestBit = ((CRC AND 32768) = 32768) XOR ((ByteVal AND Power(J)) = _ Power( J)) CRC = ((CRC AND 32767&) * 2&) IF TestBit THEN CRC = CRC XOR &H1021& ' <-- This for 16 Bit CRC NEXT J NEXT I CRC16& = CRC 'Return the Word Value END FUNCTION DEFSNG A-Z FUNCTION CRC32& (B$) 'Calculates CRC for Each Block DIM Power(0 TO 7) 'For the 8 Powers of 2 DIM CRC AS LONG FOR I = 0 TO 7 'Calculate Once Per Block to Power(I) = 2 ^ I ' Increase Speed Within FOR J NEXT I ' Loop CRC = 0 'Reset for Each Text Block FOR I = 1 TO LEN(B$) 'Calculate for Length of Block ByteVal = ASC(MID$(B$, I, 1)) FOR J = 7 TO 0 STEP -1 TestBit = ((CRC AND 32768) = 32768) XOR ((ByteVal AND Power(J)) =_ Power(J )) CRC = ((CRC AND 32767&) * 2&) IF TestBit THEN CRC = CRC XOR &H8005& ' <-- This for 32 Bit CRC NEXT J NEXT I CRC32& = CRC 'Return the Word Value END FUNCTION === END === If you'd like a FAST ASM version, just ask. Coridon Henshaw / Sirrus Software / QBCIMR FTSC Standards Technician / SM DEV --- GEcho 1.00 * Origin: TCS Concordia - Mail Only - Toronto, Ontario (1:250/820) SEEN-BY: 1/211 11/2 4 13/13 101/1 108/89 109/25 110/69 114/5 123/19 124/1 SEEN-BY: 153/752 154/40 77 157/2 159/100 125 430 950 203/23 209/209 280/1 SEEN-BY: 390/1 396/1 15 397/2 2230/100 3603/20